package web.jsoft.com;

import java.util.Date;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.jdo.PersistenceManager;
import com.google.appengine.api.datastore.Key; 
import com.google.appengine.api.datastore.KeyFactory;
import dao.jsoft.com.PMF;
import domain.jsoft.com.User;

@ManagedBean
@RequestScoped
public class AdduserBean {
	private String lastName;
	private String firstName;
	private String email;
	private Date birthday;
	private TestSpring testSpring;
	
	public TestSpring getTestSpring(){
		return this.testSpring;
	}
	
	public void setTestSpring(TestSpring testSpring){
		this.testSpring = testSpring;
	}		
	
	public void setBirthday(Date birthday){
		this.birthday = birthday;
	}
	
	public Date getBirthday(){
		return this.birthday;
	}
	
	public void setLastName(String lastName){
		this.lastName = lastName;
	}
	
	public String getLastName(){
		return this.lastName;
	}
	
	public void setFirstName(String firstName){
		this.firstName = firstName;
	}
	
	public String getFirstName(){
		return this.firstName;
	}
	
	public void setEmail(String email){
		this.email = email;
	}
	
	public String getEmail(){
		return this.email;
	}
	
	public String addUser(){
		System.out.println(testSpring.getPropString());
		PersistenceManager pm = PMF.get().getPersistenceManager();       
		Key key = KeyFactory.createKey(User.class.getSimpleName(), email); 
		User u = new User();   
		u.setFirstName(firstName);
		u.setLastName(lastName);
		u.setKey(key);
		u.setEmail(email);
		try {             
			pm.makePersistent(u);     
			pm.flush();
		} 
		finally {             
			pm.close();         
		}
		return "success";
	}
}
